﻿/* 
 * CIFSDesign.cs
 * 
 * Author - Ankit Gupta and Gaurav Aggarwal
 * 
 * This file handles component design of CIFS tab.
 * 
 */

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
using Microsoft.Win32;
using System.Text;

partial class CIFSControl : UserControl
{
    public GroupBox grpbox = new GroupBox();
    public DataGridView datagrid = new DataGridView();
    public DataGridViewTextBoxColumn Column1 = new DataGridViewTextBoxColumn();
    public DataGridViewTextBoxColumn Column2 = new DataGridViewTextBoxColumn();
    public Label netbiosNameLabel = new Label();
    public Label locateAdapterLabel = new Label();
    public Label multiplexedRequestsLabel = new Label();
    public Label maximumVirtualCircuitsLabel = new Label();
    public Label authenticationLevelLabel = new Label();
    public Label subMountLabel = new Label();
    public Label sharenameLabel = new Label();
    public Label policyLabel = new Label();
    public TextBox netbiosNameTextBox = new TextBox();
    public TextBox multiplexedRequestsTextBox = new TextBox();
    public TextBox maximumVirtualCircuitsTextBox = new TextBox();
    public TextBox sharenameTextBox = new TextBox();
    public CheckBox locateAdapterCheckBox = new CheckBox();
    public CheckBox subMountCheckBox = new CheckBox();
    public ComboBox authenticationLevelComboBox = new ComboBox();
    public ComboBox policyComboBox = new ComboBox();
    public Button buttonAddModify = new Button();
    public Button buttonRemove = new Button();
    public Button applyButton = new Button();
    public Button cancelButton = new Button();

    RegistryKey serviceParameters = Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\Services\\TransarcAFSDaemon\\Parameters", true);
    RegistryKey shareNames = Registry.LocalMachine.OpenSubKey("SOFTWARE\\OpenAFS\\Client\\CSCPolicy", true);
    Array shareName;
    int shareCount;

    public CIFSControl()
    {
        if (shareNames != null)
        {
            shareName = shareNames.GetValueNames();
            shareCount = shareNames.ValueCount;
        }

        grpbox.Location = new System.Drawing.Point(20, 250);
        grpbox.Name = "grpBox";
        grpbox.Size = new System.Drawing.Size(520, 125);
        grpbox.Text = "Client Side Caching Policy";

        netbiosNameLabel.Location = new System.Drawing.Point(20, 20);
        netbiosNameLabel.Name = "netbiosNameLabel";
        netbiosNameLabel.Text = "NetBIOS name";

        // NetBios Name
        netbiosNameTextBox.Location = new System.Drawing.Point(300, 20);
        netbiosNameTextBox.Name = "netbiosNameTextBox";
        netbiosNameTextBox.Size = new System.Drawing.Size(240, 20);
        netbiosNameTextBox.Text = serviceParameters.GetValue("NetbiosName", "AFS").ToString();

        // Locate LAN Adapter
        locateAdapterCheckBox.Location = new System.Drawing.Point(20, 57);
        locateAdapterCheckBox.Name = "locateAdapterCheckBox";
        locateAdapterCheckBox.Size = new System.Drawing.Size(20, 20);
        locateAdapterCheckBox.Checked = Convert.ToBoolean((int)serviceParameters.GetValue("NoFindLanaByName", 0));

        locateAdapterLabel.Location = new System.Drawing.Point(40, 60);
        locateAdapterLabel.Name = "locateAdapterLabel";
        locateAdapterLabel.Size = new System.Drawing.Size(300, 15);
        locateAdapterLabel.Text = "Do not attempt to Locate LAN adapter named \"AFS\"";

        // Maximum Number of Multiplexed SMB Requests
        multiplexedRequestsLabel.Location = new System.Drawing.Point(20, 100);
        multiplexedRequestsLabel.Name = "multiplexedRequestsLabel";
        multiplexedRequestsLabel.Size = new System.Drawing.Size(250, 15);
        multiplexedRequestsLabel.Text = "Maximum number of Multiplexed SMB requests";

        multiplexedRequestsTextBox.Location = new System.Drawing.Point(390, 100);
        multiplexedRequestsTextBox.Name = "multiplexedRequestsTextBox";
        multiplexedRequestsTextBox.Size = new System.Drawing.Size(150, 20);
        multiplexedRequestsTextBox.Text = ((int)serviceParameters.GetValue("MaxMpxRequests", 50)).ToString();

        // Maximum Number of SMB VirtualCircuits
        maximumVirtualCircuitsLabel.Location = new System.Drawing.Point(20, 140);
        maximumVirtualCircuitsLabel.Name = "maximumVirtualCircuitsLabel";
        maximumVirtualCircuitsLabel.Size = new System.Drawing.Size(250, 15);
        maximumVirtualCircuitsLabel.Text = "Maximum number of SMB virtual circuits";

        maximumVirtualCircuitsTextBox.Location = new System.Drawing.Point(390, 140);
        maximumVirtualCircuitsTextBox.Name = "maximumVirtualCircuitsTextBox";
        maximumVirtualCircuitsTextBox.Size = new System.Drawing.Size(150, 20);
        maximumVirtualCircuitsTextBox.Text = ((int)serviceParameters.GetValue("MaxVCPerServer", 100)).ToString();

        // SMB Authentication Level
        authenticationLevelLabel.Location = new System.Drawing.Point(20, 180);
        authenticationLevelLabel.Name = "authenticationLevelLabel";
        authenticationLevelLabel.Size = new System.Drawing.Size(250, 15);
        authenticationLevelLabel.Text = "Required SMB authentication level";

        authenticationLevelComboBox.Location = new System.Drawing.Point(390, 180);
        authenticationLevelComboBox.Name = "authenticationLevelComboBox";
        authenticationLevelComboBox.Size = new System.Drawing.Size(150, 20);
        authenticationLevelComboBox.Items.Add("No authentication");
        authenticationLevelComboBox.Items.Add("NTLM authentication");
        authenticationLevelComboBox.Items.Add("Extended(GSS SPNEGO)");
        authenticationLevelComboBox.SelectedIndex = (int)serviceParameters.GetValue("smbAuthType", 2);

        // Enable/Disable Submount
        subMountCheckBox.Location = new System.Drawing.Point(20, 217);
        subMountCheckBox.Name = "subMountCheckBox";
        subMountCheckBox.Size = new System.Drawing.Size(20, 20);
        subMountCheckBox.Checked = Convert.ToBoolean((int)serviceParameters.GetValue("AllSubmount", 1));

        subMountLabel.Location = new System.Drawing.Point(40, 220);
        subMountLabel.Name = "subMountLabel";
        subMountLabel.Size = new System.Drawing.Size(200, 15);
        subMountLabel.Text = "Enable \"all\" submount";

        datagrid.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
        datagrid.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { Column1, Column2 });
        int i;
        if (shareNames != null) for (i = 0; i < shareCount; i++) datagrid.Rows.Add(shareName.GetValue(i).ToString(), shareNames.GetValue(shareName.GetValue(i).ToString()));
        datagrid.Location = new System.Drawing.Point(30, 270);
        datagrid.RowHeadersVisible = false;
        datagrid.BackgroundColor = Color.White;
        datagrid.ReadOnly = true;
        datagrid.Name = "datagrid";
        datagrid.Size = new System.Drawing.Size(280, 89);

        Column1.HeaderText = "Share Name";
        Column1.Name = "Column1";
        Column1.Width = 140;

        Column2.HeaderText = "Policy";
        Column2.Name = "Column2";
        Column2.Width = 137;

        sharenameLabel.Location = new System.Drawing.Point(330, 275);
        sharenameLabel.Name = "sharenameLabel";
        sharenameLabel.Size = new System.Drawing.Size(70, 15);
        sharenameLabel.Text = "Share name";

        // Share Name
        sharenameTextBox.Location = new System.Drawing.Point(400, 275);
        sharenameTextBox.Name = "sharenameTextBox";
        sharenameTextBox.Size = new System.Drawing.Size(130, 20);
        sharenameTextBox.Text = "";

        policyLabel.Location = new System.Drawing.Point(330, 305);
        policyLabel.Name = "policyLabel";
        policyLabel.Size = new System.Drawing.Size(70, 15);
        policyLabel.Text = "Policy";

        // Policy
        policyComboBox.Location = new System.Drawing.Point(400, 305);
        policyComboBox.Name = "policyComboBox";
        policyComboBox.Size = new System.Drawing.Size(130, 20);
        policyComboBox.Items.Add("manual");
        policyComboBox.Items.Add("programs");
        policyComboBox.Items.Add("documents");
        policyComboBox.Items.Add("disable");

        // Add/Modify Button
        buttonAddModify.Location = new System.Drawing.Point(330, 335);
        buttonAddModify.Name = "buttonAddModify";
        buttonAddModify.Size = new System.Drawing.Size(80, 23);
        buttonAddModify.Text = "Add/Modify";
        buttonAddModify.Click += new System.EventHandler(buttonAddModify_Click);

        // Remove Button
        buttonRemove.Location = new System.Drawing.Point(450, 335);
        buttonRemove.Name = "buttonRemove";
        buttonRemove.Size = new System.Drawing.Size(80, 23);
        buttonRemove.Text = "Remove";
        buttonRemove.Click += new System.EventHandler(buttonRemove_Click);

        // Apply button
        applyButton.Location = new System.Drawing.Point(20, 460);
        applyButton.Name = "applyButton";
        applyButton.Size = new System.Drawing.Size(100, 23);
        applyButton.Text = "Apply";
        applyButton.Click += new System.EventHandler(applyButton_Click);

        // Cancel button
        cancelButton.Location = new System.Drawing.Point(140, 460);
        cancelButton.Name = "cancelButton";
        cancelButton.Size = new System.Drawing.Size(100, 23);
        cancelButton.Text = "Cancel";
        cancelButton.Click += new System.EventHandler(cancelButton_Click);
    }
}